package com.arpa.qimen.controller;
/*

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.XmlUtil;
import com.arpa.ntocc.common.common.exception.ServiceException;
import com.arpa.ntocc.common.domain.entity.Shipment;
import com.arpa.ntocc.common.service.IShipmentService;
import com.arpa.wms.domain.entity.Delivery;
import com.arpa.wms.domain.entity.DeliveryItem;
import com.arpa.wms.domain.entity.Goods;
import com.arpa.wms.mapper.DeliveryItemMapper;
import com.arpa.wms.mq.provider.DeliveryorderConfirmSender;
import com.arpa.wms.mq.provider.InboundConfirmSender;
import com.arpa.wms.mq.provider.OutboundConfirmSender;
import com.arpa.wms.mq.provider.ReturnInboundConfirmSender;
import com.arpa.wms.service.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qimen.api.DefaultQimenClient;
import com.qimen.api.QimenClient;
import com.qimen.api.request.*;
import com.qimen.api.response.DeliveryorderConfirmResponse;
import io.swagger.annotations.Api;
import lombok.extern.log4j.Log4j2;
import net.sf.json.JSONObject;
import net.sf.json.xml.XMLSerializer;
import org.checkerframework.checker.units.qual.A;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

*/
/**
 * 奇门接口 api
 * @author jinss
 * @date 2020-11-04 13:25:47
 **//*

@Api(tags = "奇门接口 api")
@RestController
@RequestMapping(value="/api/qimen", produces = "application/json;charset=UTF-8")
@Log4j2
public class QiMenController {
    @Autowired
    private IGoodsService goodsService;
    @Autowired
    private IBrandService brandService;
    @Autowired
    private IGoodsTypeService goodsTypeService;
    @Autowired
    private IGoodsUnitService goodsUnitService;
    @Autowired
    private IGoodsUnitConversionService goodsUnitConversionService;
    @Autowired
    private IShipmentService shipmentService;
    @Autowired
    private InboundConfirmSender inboundConfirmSender;
    @Autowired
    private ReturnInboundConfirmSender returnInboundConfirmSender;
    @Autowired
    private OutboundConfirmSender outboundConfirmSender;
    @Resource
    private DeliveryItemMapper deliveryItemMapper;
    @Autowired
    private DeliveryorderConfirmSender deliveryorderConfirmSender;

    @ResponseBody
    @RequestMapping(value="/realization",produces="text/xml;charset=UTF-8")
    public byte[] apiRealization(HttpServletRequest request, HttpServletResponse response) {
        // AppKey
        String appKeyVal = request.getParameter("app_key");
        System.out.println("--------------------------appKeyVal 开始----------------------------------");
        System.out.println(appKeyVal);
        System.out.println("--------------------------appKeyVal 结束----------------------------------");
        // API接口名称
        String methodVal = request.getParameter("method");
        System.out.println("--------------------------method 开始----------------------------------");
        System.out.println(methodVal);
        System.out.println("--------------------------method 结束----------------------------------");
        // 时间戳，格式：yyyy-MM-dd HH:mm:ss
        String timestampVal = request.getParameter("timestamp");
        // 请求签名
        String signVal = request.getParameter("sign");
        System.out.println("--------------------------sign 开始----------------------------------");
        System.out.println(signVal);
        System.out.println("--------------------------sign 结束----------------------------------");
        byte[] result = null;
        Map<String, Object> resultMap = new HashMap<>();
        InputStream inputStream;
        StringBuffer sb = new StringBuffer();
        try {
            // 解析xml参数
            inputStream = request.getInputStream();
            String s;
            BufferedReader in = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
            while ((s = in.readLine()) != null) {
                sb.append(s);
            }
            in.close();
            inputStream.close();
            if(sb.length() > 0) {
                Map<String, Object> xmlToMap = XmlUtil.xmlToMap(sb.toString());
                // json格式的报文参数
//                JSONObject xmlToJson = JSON.parseObject((String) xmlForJson(sb.toString()));
//                JSONObject xmlToJson = JSONObject.fromObject(xmlForJson(sb.toString()));
                System.out.println("--------------------------xml参数 开始----------------------------------");
                System.out.println(sb.toString());
                System.out.println("--------------------------xml参数 结束----------------------------------");
                if(StrUtil.isNotBlank(methodVal)) {
                    switch (methodVal) {
                        case "deliveryorder.create":
                            // 发货单创建接口
                            //resultMap = ;
                            break;
                        case "entryorder.create":
                            // 入库单创建接口
                            //resultMap = ;
                            resultMap.put("message", "入库单创建成功！");
                            resultMap.put("flag", "success");
                            resultMap.put("code", "0");
                            resultMap.put("entryOrderId", "EID1234");
                            break;
                        case "stockout.create":
                            // 出库单创建接口
                            //resultMap = ;
                            break;
                        case "order.cancel":
                            // 单据取消接口
                            //resultMap = ;
                            break;
                        case "singleitem.synchronize":
                            // 商品同步接口
                            singleGoodsSaveOrUpdate(xmlToMap,resultMap);
                            break;
                        case "items.synchronize":
                             // 商品同步接口 (批量)
                            batchGoodsSaveOrUpdate(xmlToMap,resultMap);
                            break;
                        default:
                            resultMap.put("message", "接口名称method填写有误！");
                            resultMap.put("flag", "failure");
                            resultMap.put("code", "500");
                            break;
                    }
                }else {
                    resultMap.put("message", "接口名称method不能为空！");
                    resultMap.put("flag", "failure");
                    resultMap.put("code", "500");
                }

                log.info("返回xml格式的结果为："+multilayerMapToXml(resultMap, false));
                result = multilayerMapToXml(resultMap, false).getBytes("UTF-8");
            }else {
                result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>".getBytes("UTF-8");
            }
        } catch (Exception e) {
            resultMap.put("flag", "failure");
            resultMap.put("code", "500");
            resultMap.put("message", "操作失败，参数有误！");
            try {
                result = multilayerMapToXml(resultMap, false).getBytes("UTF-8");
            } catch (UnsupportedEncodingException e1) {
                return null;
            }
        }
        return result;
    }

    */
/**
     * xml字符串转json字符串
     * @param xml
     * @return
     *//*

    private Object xmlForJson(String xml) {
        XMLSerializer xmlSerializer = new XMLSerializer();
        String resutStr = xmlSerializer.read(xml).toString();
        return resutStr;
    }

    */
/**
     * (多层)map转换为xml格式字符串
     *
     * @param map 需要转换为xml的map
     * @param isCDATA 是否加入CDATA标识符 true:加入 false:不加入
     * @return xml字符串
     * @throws UnsupportedEncodingException
     *//*

    public static String multilayerMapToXml(Map<String, Object> map, boolean isCDATA) throws UnsupportedEncodingException{
        String parentName = "response";
        Document doc = DocumentHelper.createDocument();
        doc.addElement(parentName);
        String xml = recursionMapToXml(doc.getRootElement(), parentName, map, isCDATA);
        return formatXML(xml);
    }

    */
/**
     * multilayerMapToXml核心方法，递归调用
     *
     * @param element 节点元素
     * @param parentName 根元素属性名
     * @param map 需要转换为xml的map
     * @param isCDATA 是否加入CDATA标识符 true:加入 false:不加入
     * @return xml字符串
     *//*

    @SuppressWarnings("unchecked")
    private static String recursionMapToXml(Element element, String parentName, Map<String, Object> map, boolean isCDATA) {
        Element xmlElement = element.addElement(parentName);
        map.keySet().forEach(key -> {
            Object obj = map.get(key);
            if (obj instanceof Map) {
                recursionMapToXml(xmlElement, key, (Map<String, Object>)obj, isCDATA);
            } else {
                String value = obj == null ? "" : obj.toString();
                if (isCDATA) {
                    xmlElement.addElement(key).addCDATA(value);
                } else {
                    xmlElement.addElement(key).addText(value);
                }
            }
        });
        return xmlElement.asXML();
    }

    */
/**
     * 格式化xml,显示为容易看的XML格式
     *
     * @param xml 需要格式化的xml字符串
     * @return
     *//*

    public static String formatXML(String xml) {
        String requestXML = null;
        try {
            // 拿取解析器
            SAXReader reader = new SAXReader();
            Document document = reader.read(new StringReader(xml));
            if (null != document) {
                StringWriter stringWriter = new StringWriter();
                // 格式化,每一级前的空格
                OutputFormat format = new OutputFormat("	", true);
                // xml声明与内容是否添加空行
                format.setNewLineAfterDeclaration(false);
                // 是否设置xml声明头部
                format.setSuppressDeclaration(false);
                // 是否分行
                format.setNewlines(true);
                XMLWriter writer = new XMLWriter(stringWriter, format);
                writer.write(document);
                writer.flush();
                writer.close();
                requestXML = stringWriter.getBuffer().toString();
            }
            return requestXML;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    */
/**
     * 同步时，根据商品编码判断是插入还是更新
     * @param xmlToMap
     * @param resultMap
     *//*

    private void batchGoodsSaveOrUpdate(Map<String,Object> xmlToMap,Map<String, Object> resultMap ){
        String shipmentPartyCode = (String) xmlToMap.get("ownerCode");
        //根据货主校验是否能够同步数据
        validateCanBatchSynchronize(shipmentPartyCode);
        ItemsSynchronizeRequest request = BeanUtil.mapToBean(xmlToMap, ItemsSynchronizeRequest.class, false);
        if(ObjectUtil.isNull(request)){
            resultMap.put("flag", "failure");
            resultMap.put("code", "500");
            resultMap.put("message", "商品同步失败，没有请求信息");
            return;
        }
        //过滤掉单位和产品类型为空的item
        List<ItemsSynchronizeRequest.Item> items = request.getItems().stream().filter(item -> StrUtil.isNotEmpty(item.getStockUnit())
                    && StrUtil.isNotEmpty(item.getCategoryId())).collect(Collectors.toList());
        request.setItems(items);
        String shipmentName = shipmentService.getOne(new QueryWrapper<Shipment>().lambda().eq(Shipment::getPartyCode, shipmentPartyCode)).getUserName();
        //单位map，主键是shipmentPartyCode_unitName,value is unitCode(单位编码)
        Map<String, String> unitMap = new HashMap<>();
        try {
            //批量添加商品基本单位
            goodsUnitService.batchGoodsUnitSave(request,shipmentName,unitMap);
            //批量添加或者更新商品
            goodsService.batchGoodsSaveOrUpdate(request,shipmentName,unitMap);
            //批量添加或者更新商品品牌
            brandService.batchGoodsBrandSave(request,shipmentName);
            //批量添加或者更新商品类型
            goodsTypeService.batchGoodsTypeSave(request);
            //批量添加或者更新商品单位换算
            goodsUnitConversionService.batchGoodsUnitConversionSave(request,unitMap);
            log.info("<<<<< 商品同步成功 >>>>>");
            resultMap.put("message", "商品同步成功！");
            resultMap.put("flag", "success");
            resultMap.put("code", "0");
        } catch (Exception e) {
            resultMap.put("message", "商品同步失败！");
            resultMap.put("flag", "failure");
            resultMap.put("code", "500");
            log.error(e);
        }
    }

    */
/**
     * 单个商品同步时，根据商品编码判断是插入还是更新
     * @param xmlToMap
     * @param resultMap
     *//*

    private void singleGoodsSaveOrUpdate(Map<String,Object> xmlToMap,Map<String, Object> resultMap ){
        log.info("同步过来的数据为>>>{}",xmlToMap);
        SingleitemSynchronizeRequest request = BeanUtil.mapToBean(xmlToMap, SingleitemSynchronizeRequest.class, false);
        if(ObjectUtil.isNull(request)){
            resultMap.put("flag", "failure");
            resultMap.put("code", "500");
            resultMap.put("message", "商品同步失败，没有请求信息");
            return;
        }
        String shipmentPartyCode = request.getOwnerCode();
        //根据货主、商品单位校验是否能够同步数据
        validateCanSynchronize(request);

        String shipmentName = shipmentService.getOne(new QueryWrapper<Shipment>().lambda().eq(Shipment::getPartyCode, shipmentPartyCode)).getUserName();
        //单位map，主键是shipmentPartyCode_unitName,value is unitCode(单位编码)
        Map<String, String> unitMap = new HashMap<>();
        try {
            //添加商品基本单位
            goodsUnitService.singleGoodsUnitSave(request,shipmentName,unitMap);
            //添加或者更新商品
            goodsService.singleGoodsSaveOrUpdate(request,shipmentName,unitMap);
            //添加或者更新商品品牌
            brandService.singleGoodsBrandSave(request,shipmentName);
            //添加或者更新商品类型
            goodsTypeService.singleGoodsTypeSave(request);
            //添加或者更新商品单位换算
            goodsUnitConversionService.singleGoodsUnitConversionSave(request,unitMap);
            Goods goods = goodsService.getOne(new QueryWrapper<Goods>().lambda().eq(Goods::getGoodCode, request.getItem()
                    .getItemCode()).eq(Goods::getShipmentCode, shipmentPartyCode));
            log.info("<<<<< 商品同步成功 >>>>>");
            resultMap.put("message", "商品同步成功！");
            resultMap.put("flag", "success");
            resultMap.put("code", "0");
            resultMap.put("itemId", goods.getId());
        } catch (Exception e) {
            resultMap.put("message", "商品同步失败！");
            resultMap.put("flag", "failure");
            resultMap.put("code", "500");
            log.error(e);
        }

    }


    */
/**
     * 根据货主校验是否能够同步数据
     * @param request
     *//*

    private void validateCanSynchronize(SingleitemSynchronizeRequest request) {
        Shipment shipment = shipmentService.getOne(new QueryWrapper<Shipment>().lambda().eq(Shipment::getPartyCode, request.getOwnerCode()));
        String unitName = request.getItem().getStockUnit();
        if (ObjectUtil.isNull(shipment)) {
            throw new ServiceException("货主表中没有同步的货主信息");
        }
        //检验单位名称，同步过来的单位名称为空时，不能进行商品同步
        if (StrUtil.isEmpty(unitName)) {
            throw new ServiceException("商品单位为空，不能进行商品同步");
        }
        //检验商品类别，同步过来的商品类别id为空时，不能进行商品同步
        if (StrUtil.isEmpty(request.getItem().getCategoryId())) {
            throw new ServiceException("商品类别id为空，不能进行商品同步");
        }
    }

    */
/**
     * 根据货主校验是否能够同步数据
     * @param shipmentCode
     *//*

    private void validateCanBatchSynchronize(String shipmentCode) {
        Shipment shipment = shipmentService.getOne(new QueryWrapper<Shipment>().lambda().eq(Shipment::getPartyCode, shipmentCode));
        if (ObjectUtil.isNull(shipment)) {
            throw new ServiceException("货主表中没有同步的货主信息");
        }
    }

    @RequestMapping("/entryOrderConfirm")
    public void entryOrderConfirm() {
        List<EntryorderConfirmRequest.OrderLine> orderLines = new ArrayList<>();
        EntryorderConfirmRequest req = new EntryorderConfirmRequest();
        req.setCustomerId("stub-cust-code");
        req.setVersion("2.0");
        EntryorderConfirmRequest.EntryOrder entryOrder = new EntryorderConfirmRequest.EntryOrder();
        entryOrder.setContractCode("奇门仓储字段,说明,string(50),,");
        //入库单号
        entryOrder.setEntryOrderCode("CD202102230012");
        //	货主编码
        entryOrder.setOwnerCode("54225ff22f224aa198689e4e2af853f7");
        //仓库编码(统仓统配等无需ERP指定仓储编码的情况填OTHER)
        entryOrder.setWarehouseCode("ck2021022001");
        //外部业务编码(消息ID;用于去重;ISV对于同一请求;分配一个唯一性的编码。用来保证因为网络等原因导致重复传输;请求 不会被重复处理)
        entryOrder.setOutBizCode(IdUtil.simpleUUID());
        //	入库单状态(NEW-未开始处理;ACCEPT-仓库接单;PARTFULFILLED-部分收货完成;FULFILLED-收货完成;EXCEPTION-异 常;CANCELED-取消;CLOSED-关闭;REJECT-拒单;CANCELEDFAIL-取消失败;只传英文编码)
        entryOrder.setStatus("FULFILLED");
        //店铺名称
        entryOrder.setShopNick("奇门测试店铺");
        //店铺编码
        entryOrder.setShopCode("qimenTestShop");
        entryOrder.setOrderType("CGRK");
        entryOrder.setEntryOrderType("CGRK");
        entryOrder.setExpectStartTime("2021-02-23 12:00:01");
        entryOrder.setExpectEndTime("2021-02-23 18:00:01");
        EntryorderConfirmRequest.OrderLine orderLine = new EntryorderConfirmRequest.OrderLine();
        //货主编码
        orderLine.setOwnerCode("54225ff22f224aa198689e4e2af853f7");
        //商品编码
        orderLine.setItemCode("20210220");
        orderLine.setOutBizCode("O123");
        orderLine.setOrderLineNo("EL123");
        orderLine.setOwnerCode("O123");
        orderLine.setItemCode("20210220");
        orderLine.setItemId("CI123");
        orderLine.setItemName("测试0220");
        orderLine.setPlanQty(12L);
        orderLine.setInventoryType("ZP");
        orderLine.setActualQty(12L);
        orderLine.setProductDate("2017-09-09");
        orderLine.setExpireDate("2017-09-09");
        orderLine.setProduceCode("P1234");
        orderLine.setBatchCode("PCODE123");
        orderLines.add(orderLine);
        List<EntryorderConfirmRequest.Batch> batchs = new ArrayList<>();
        EntryorderConfirmRequest.Batch batch1 = new EntryorderConfirmRequest.Batch();
        EntryorderConfirmRequest.Batch batch2 = new EntryorderConfirmRequest.Batch();
        batchs.add(batch1);
        batchs.add(batch2);
        EntryorderConfirmRequest.SnList snList = new EntryorderConfirmRequest.SnList();
        List<String> sn = new ArrayList<>();
        sn.add("sn1");
        sn.add("sn2");
        snList.setSn(sn);
        req.setEntryOrder(entryOrder);
        req.setOrderLines(orderLines);
        Map<String, Object> orderConfirm = new HashMap<>();
        orderConfirm = BeanUtil.beanToMap(req);
//        orderConfirm.put("entryOrder",entryOrder);
//        orderConfirm.put("orderLines", orderLines);
        JSONObject json = JSONObject.fromObject(req);

        JSONObject jsonObject = JSONObject.fromObject(json.toString());
        System.out.println("jsonObject is "+jsonObject );


        inboundConfirmSender.sendConfirm(req);

    }

    @RequestMapping("/returnOrderConfirm")
    public void returnOrderConfirm() {
        List<ReturnorderConfirmRequest.OrderLine> orderLines = new ArrayList<>();
        ReturnorderConfirmRequest req = new ReturnorderConfirmRequest();
        req.setCustomerId("stub-cust-code");
        req.setVersion("2.0");
        ReturnorderConfirmRequest.ReturnOrder entryOrder = new ReturnorderConfirmRequest.ReturnOrder();
        //入库单号
        entryOrder.setReturnOrderCode("SH202102250002");
        //	货主编码
        entryOrder.setOwnerCode("37513e93726111ebb5bffa163e4beea3");
        //仓库编码(统仓统配等无需ERP指定仓储编码的情况填OTHER)
        entryOrder.setWarehouseCode("ck2021022001");
        //外部业务编码(消息ID;用于去重;ISV对于同一请求;分配一个唯一性的编码。用来保证因为网络等原因导致重复传输;请求 不会被重复处理)
        entryOrder.setOutBizCode(IdUtil.simpleUUID());
        entryOrder.setOrderType("CGRK");
        ReturnorderConfirmRequest.OrderLine orderLine = new ReturnorderConfirmRequest.OrderLine();
        //货主编码
        orderLine.setOwnerCode("37513e93726111ebb5bffa163e4beea3");
        //商品编码
        orderLine.setItemCode("20210220");
        orderLine.setOutBizCode("O123");
        orderLine.setOrderLineNo("EL123");
        orderLine.setOwnerCode("O123");
        orderLine.setItemId("CI123");
        orderLine.setItemName("测试0220");
        orderLine.setPlanQty(15L);
        orderLine.setInventoryType("ZP");
        orderLine.setActualQty("15");
        orderLine.setProductDate("2017-09-09");
        orderLine.setExpireDate("2017-09-09");
        orderLine.setProduceCode("P1234");
        orderLine.setBatchCode("PCODE123");
        orderLines.add(orderLine);
        List<ReturnorderConfirmRequest.Batch> batchs = new ArrayList<>();
        ReturnorderConfirmRequest.Batch batch1 = new ReturnorderConfirmRequest.Batch();
        ReturnorderConfirmRequest.Batch batch2 = new ReturnorderConfirmRequest.Batch();
        batchs.add(batch1);
        batchs.add(batch2);
        ReturnorderConfirmRequest.SnList snList = new ReturnorderConfirmRequest.SnList();
        List<String> sn = new ArrayList<>();
        sn.add("sn1");
        sn.add("sn2");
        snList.setSn(sn);
        req.setReturnOrder(entryOrder);
        req.setOrderLines(orderLines);
        Map<String, Object> orderConfirm = new HashMap<>();
        orderConfirm = BeanUtil.beanToMap(req);
//        orderConfirm.put("entryOrder",entryOrder);
//        orderConfirm.put("orderLines", orderLines);
        JSONObject json = JSONObject.fromObject(req);

        JSONObject jsonObject = JSONObject.fromObject(json.toString());
        System.out.println("jsonObject is "+jsonObject );
        req.setCustomerId("");

        returnInboundConfirmSender.sendConfirm(req);
    }


    */
/**
     * 发货单确认接口
     *//*

    @RequestMapping("/deliveryOrderConfirm")
    @ResponseBody
    public String deliveryOrderConfirm() {
        Delivery delivery = new Delivery();
        delivery.setCode("FH202103160000009");
        delivery.setDeliveryOrderCode("XD210316000280");
        delivery.setWarehouseCode("0ea78dd07702404abc16012732ec6cae");
        delivery.setOrderType("JYCK");
        String customerId = "37513e93726111ebb5bffa163e4beea3";
        log.info("订单出库完成发送确认信息：{}", delivery.getCode());
        DeliveryorderConfirmRequest req = new DeliveryorderConfirmRequest();
        req.setCustomerId(customerId);
        req.setVersion("2.0");
        DeliveryorderConfirmRequest.DeliveryOrder deliveryOrder = new DeliveryorderConfirmRequest.DeliveryOrder();
        // 出库单号
        deliveryOrder.setDeliveryOrderCode(delivery.getDeliveryOrderCode());
        // 仓库编码
        deliveryOrder.setWarehouseCode(delivery.getWarehouseCode());
        // 出库单类型
        deliveryOrder.setOrderType(delivery.getOrderType());


        // 商品列表
        List<DeliveryorderConfirmRequest.Item> items = new ArrayList<>();
        List<DeliveryItem> deliveryItemList = deliveryItemMapper.selectList(new QueryWrapper<DeliveryItem>().lambda().eq(DeliveryItem::getDeliveryCode, delivery.getCode()));
        deliveryItemList.forEach(e -> {
            DeliveryorderConfirmRequest.Item item = new DeliveryorderConfirmRequest.Item();
            // 商品编码
            item.setItemCode(e.getGoodCode());
            // 包裹内该商品数量
            item.setQuantity(e.getOutboundQuantity().longValue());
            items.add(item);
        });

        // 包裹信息
        List<DeliveryorderConfirmRequest.Package> packages = new ArrayList<>();
        DeliveryorderConfirmRequest.Package package1 = new DeliveryorderConfirmRequest.Package();
        // 物流公司编码
        package1.setLogisticsCode(delivery.getLogisticsCode());
//        package1.setLogisticsCode("HHTT");
        // 运单号
        package1.setExpressCode(delivery.getWaybillCode());
        package1.setItems(items);
        packages.add(package1);

//        deliveryOrder.setPackages(packages);
        req.setPackages(packages);
        deliveryOrder.setItems(items);

        // 单据列表
        List<DeliveryorderConfirmRequest.OrderLine> orderLines = new ArrayList<>();
        deliveryItemList.stream().forEach(e -> {
            DeliveryorderConfirmRequest.OrderLine orderLine = new DeliveryorderConfirmRequest.OrderLine();
            // 商品编码
            orderLine.setItemCode(e.getGoodCode());
            // 应发商品数量
            orderLine.setPlanQty((e.getPlanQuantity().intValue()) + "");
            // 实发商品数量
            orderLine.setActualQty((e.getOutboundQuantity().intValue()) + "");
            orderLine.setActualPrice(e.getActualPrice().toString());

            orderLines.add(orderLine);
        });

        req.setDeliveryOrder(deliveryOrder);
        req.setOrderLines(orderLines);
        System.out.println("XmlUtil.beanToXml(req)"+XmlUtil.beanToXml(req));
        System.out.println("XmlUtil.format(XmlUtil.beanToXml(req)):"+XmlUtil.format(XmlUtil.beanToXml(req)));

        String url = "https://qimen.api.taobao.com/router/qimen/service";
        String appkey = "30899557";
        String secret = "b696ffd70818e983150e67750b4fead7";
        QimenClient client = new DefaultQimenClient(url, appkey, secret);
        String result ;
        try {
            DeliveryorderConfirmResponse rsp = client.execute(req);
            System.out.println(rsp.toString());
            log.info("发货单确认接口返回：{}", rsp.getMessage());
            result = rsp.getMessage();
        } catch (Exception e) {
            log.error("错误信息是："+e.getMessage());
            result = e.getMessage();
        }

        return result;
    }

}
*/
